feat: migrate force_json_middleware to a named middleware#8
feat: migrate force_json_middleware to a named middleware#8kerwanp wants to merge 1 commit intoadonisjs:mainfrom
Conversation
|
Also agree its probably safe to remove that middleware and just let content-negotiation do its thing +1 for deleting it ( instead of having a named middleware ) => i've also seen people having issues migrating from the API Starter Kit to Inertia and getting confused when things don't work, and this middleware was one of the reasons why |
|
I think there are many users who use Ajax or clients like Postman and never send the relevant Also, the Therefore, completely removing the middleware might not be ideal and in this case it's a matter of choosing a default.
I am okay with both the approaches. In 2nd approach, the middleware should exist but should not be registered by default. |
🔗 Linked issue
FriendsOfAdonis/FriendsOfAdonis#48
❓ Type of change
📚 Description
This pull-request removes the
ForceJsonResponseMiddlewarefrom the server middlewares and add it to the named middleware. Thestart/routes.tsis updated accordingly by providing an initialapigroup that uses this middleware.This allows library authors to perform content-negotiation without requiring users to update their existing codebase. And this is a main issue for
@foadonis/openapiwhere the content returned depends on theAcceptheader allowing them to use the same route for documentation UI and in tools likeopenapi-typescript.On a side not I think this middleware should not exist at all. Libraries should instead rely on content negotiation as it is already something managed by browsers.
For example, here is the default Accept header on Chrome
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7*/*With the following example,
Acceptishtmlon document request andjsonon fetch request.📝 Checklist